package com.pwrd.sframe.jdom;

/**
 * 解析xml文件
 * @Auther syc.
 * @Date 2016/10/20 14:29.
 */

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

import java.util.List;

public class JDOM {

    public static void main(String arge[]) {
        long lasting = System.currentTimeMillis();
        try {
            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(JDOM.class.getClassLoader().getResourceAsStream("beans.xml"));
            Element root = doc.getRootElement();
            List allChildren = root.getChildren("bean");
            for (int i = 0; i < allChildren.size(); i++) {
                System.out.print("bean'id is :" + ((Element) allChildren.get(i)).getAttribute("id"));
                System.out.print("bean'class is :" + ((Element) allChildren.get(i)).getAttribute("class"));
            }
            System.out.println("运行时间：" + (System.currentTimeMillis() - lasting)
                    + "毫秒");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
